<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

	<div>
			<!-- 标签 -->
   		 <!-- Nav tabs 标签导航-->
    <ul class="nav nav-tabs" role="tablist">
		<!-- 标签对应着内容 #home，#profile，#messages -->
      <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">用户列表</a></li>
      <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">用户添加</a></li>
    </ul>
		<!-- 标签的内容 -->
    <!-- Tab panes 选项卡窗格-->
    <div class="tab-content">
		<!-- 此处的id对应标签中的a的href链接 -->
      <div role="tabpanel" class="tab-pane active" id="home">
      		<div class="panel panel-info">
			    <div class="panel-body">
			    	<form id="UserInfoParams">
				    	<div class="row">
						    <div class="form-inline">
				                   <div class="col-md-4 col-sm-4 col-xs-12 mar">
										<div class="input-group">
											<span class="input-group-addon">归属公司</span><input class="form-control hidden" name="companyId" type="text"><input class="form-control" name="companyName" type="text"><span class="input-group-btn"><button class="btn btn-default" style="height:34px;" id="companyShow" type="button"><i class="fa fa-search"></i></button></span>
										</div>
									</div>
				                   <div class="col-md-4 col-sm-4 col-xs-12 mar">
										<div class="input-group">
											<span class="input-group-addon">工号</span> <input class="form-control" name="no" type="text">
										</div>
									</div>
									<div class="col-md-4 col-sm-4 col-xs-12 mar">
										<div class="input-group">
											<span class="input-group-addon">在职情况</span><select class="form-control" style="width:200px"name="delFlag"><option value="-1">全部</option><option value="0">在职</option><option value="1">离职</option></select>
										</div>
									</div>
							</div>
						</div>
						<div class="row">
							<div class="form-inline">
									<div class="col-md-4 col-sm-4 col-xs-12 mar">
										<div class="input-group">
											<span class="input-group-addon">归属部门</span><input class="form-control hidden" name="officeId" type="text"><input class="form-control" name="officeName" type="text"><span class="input-group-btn"><button class="btn btn-default" style="height:34px;" id="officeShow" type="button"><i class="fa fa-search"></i></button></span>
										</div>
									</div>
				                   	<div class="col-md-4 col-sm-4 col-xs-12 mar">
										<div class="input-group">
											<span class="input-group-addon">姓&nbsp;&nbsp;&nbsp;名</span><input class="form-control" name="name" type="text">
										</div>
									</div> 
									<div class="col-md-4 col-sm-4 col-xs-12 mar">
										<div class="input-group">
											<button class="btn btn-primary" type="button" id="findUserbtn">查询</button>
											<button class="btn btn-primary" type="button" id="outputUserExcelbtn">导出</button>
											<button class="btn btn-primary" type="button" id="inputUserExcelbtn">导入</button>
										</div>
									</div>
			                </div>
		                </div>
					</form>
			  	</div>
			  	<div id="toolbar" class="btn-group">
					<button id="btn_update" type="button" class="btn btn-default">
						<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
					</button>
					<button id="btn_delete" type="button" class="btn btn-default">
						<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
					</button>
				</div>
			    <table class="table table-bordered" id="userListTable"></table>
			</div>
      </div>
      <!-- 此处的id对应标签中的a的href链接 -->
      <div role="tabpanel" class="tab-pane" id="profile">
      	<div class="col-md-6 col-sm-6 col-xs-12 mar">
      		<form id="userform" class="form-horizontal">
	      		 <div class="col-md-12 col-sm-12 col-xs-12 mar">
	      		 	<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">归属公司</span><input class="form-control hidden" name="companyId" type="text"><input class="form-control" name="companyName" type="text"><span class="input-group-btn"><button class="btn btn-default" style="height:34px;" id="companyShow2" type="button"><i class="fa fa-search"></i></button></span>
						</div>
					</div>
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">归属部门</span><input class="form-control hidden" name="officeId" type="text"><input class="form-control" name="officeName" type="text"><span class="input-group-btn"><button class="btn btn-default" style="height:34px;" id="officeShow2" type="button"><i class="fa fa-search"></i></button></span>
						</div>
					</div>
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">姓名:</span><input type="text" name="name" class="form-control">
						</div>
					</div>
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">性别:</span><input type="radio" name="sex" value="F">女&nbsp;&nbsp;<input
								type="radio" name="sex" value="M" checked>男
						</div>
					</div>
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">工号:</span><input type="text" name="no" class="form-control">
						</div>
					</div>
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">登录名:</span><input type="text" name="loginName" class="form-control">
						</div>
					</div>
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">密码:</span><input type="password" name="password" class="form-control">
						</div>
					</div>
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">确认密码:</span><input type="password" name="repassword" class="form-control">
						</div>
					</div>
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">邮箱:</span><input type="text" name="email" class="form-control">
						</div>
					</div>
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">电话:</span><input type="text" name="phone" class="form-control">
						</div>
					</div>
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">手机:</span><input type="text" name="mobile" class="form-control">
						</div>
					</div>
				</div>
				<div class="col-md-3 col-sm-3 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">在职情况</span><select class="form-control" style="width:200px"name="delFlag"><option value="0">在职</option><option value="1">离职</option></select>
						</div>
                 	</div>
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">入职日期:</span><input type="text" name="entryTime" class="form-control Wdate" onfocus="WdatePicker({el:this, dateFmt:'yyyy-MM-dd', readOnly:true, onpicked:checkProductionDate(this)})"/>
						</div>
					</div>	
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">试用期(月):</span><input type="text" name="tryTime" class="form-control">
						</div>
					</div>
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">实际转正日:</span><input type="text" name="actualTime" class="form-control Wdate" onfocus="WdatePicker({el:this, dateFmt:'yyyy-MM-dd', readOnly:true, onpicked:checkProductionDate(this)})">
						</div>
					</div>
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">用户角色:</span><div class="col-sm-10" id="roleIds"></div>
						</div>
					</div>
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon">备注:</span><textarea class="form-control" cols="40" rows="3" name="remarks"></textarea>
						</div>
					</div>
				</div>
				<div class="col-md-12 col-sm-12 col-xs-12 mar">
					<div class="input-group">
						<button class="btn btn-primary" type="button" id="saveNewUser">保存</button>
						&nbsp;&nbsp;<input class="btn btn-default" type="reset" value="返回">
					</div>
				</div>
			</form>
      	</div>
      </div>
      <!-- profile结束 -->
    </div>  
    		<!-- 模态框组（Modal） -->
	<div>
		<!-- 模态框(companyModal) -->
		<div class="modal fade" id="companyModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		    <div class="modal-dialog">
		        <div class="modal-content">
		            <div class="modal-header">
		                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		                <h4 class="modal-title" id="myModalLabel"><font color='blue'>选择公司</font></h4>
		            </div>
		            <div class="modal-body">
		            	<div id="prot1" style="height:360px;">
						     <div class="col-md-12 col-sm-12 col-xs-12 text-center">
						     	<h4>请点击选择公司</h4>
								<ul id="treeDemo" class="ztree"></ul>
							</div>	
		        		</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		                	<button type="button" class="btn btn-primary" id ="SelectCompanyBtnSub">确定</button>
	                	</div>
		        	</div> 
				</div><!-- /.modal-content -->
		    </div><!-- /.modal -->
		</div>
		<!-- end(companyModal) -->
		
		<!-- 模态框(companyModal1) -->
		<div class="modal fade" id="companyModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		    <div class="modal-dialog">
		        <div class="modal-content">
		            <div class="modal-header">
		                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		                <h4 class="modal-title" id="myModalLabel"><font color='blue'>选择公司</font></h4>
		            </div>
		            <div class="modal-body">
		            	<div id="prot3" style="height:360px;">
						     <div class="col-md-12 col-sm-12 col-xs-12 text-center">
						     	<h4>请点击选择公司</h4>
								<ul id="treeDemo2" class="ztree"></ul>
							</div>	
		        		</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		                	<button type="button" class="btn btn-primary" id ="SelectCompanyBtnSub2">确定</button>
	                	</div>
		        	</div> 
				</div><!-- /.modal-content -->
		    </div><!-- /.modal -->
		</div>
		<!-- end(companyModal1) -->
		
		<!-- 模态框(officeModal) -->
		<div class="modal fade" id="officeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		    <div class="modal-dialog">
		        <div class="modal-content">
		            <div class="modal-header">
		                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		                <h4 class="modal-title" id="myModalLabel"><font color='blue'>选择部门</font></h4>
		            </div>
		            <div class="modal-body">
		            	<div id="prot2" style="height:360px;">
		            		<div class="col-md-12 col-sm-12 col-xs-12 text-center">
		            			<h4>请点击选择部门</h4>
								<ul id="treeDemo1" class="ztree"></ul>
							</div>	
		        		</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		                	<button type="button" class="btn btn-primary" id ="SelectOfficeBtnSub">确定</button>
	                	</div>
		        	</div> 
				</div><!-- /.modal-content -->
		    </div><!-- /.modal -->
		</div>
		<!-- end(officeModal) -->
		
		<!-- 模态框(officeModal1) -->
		<div class="modal fade" id="officeModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		    <div class="modal-dialog">
		        <div class="modal-content">
		            <div class="modal-header">
		                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		                <h4 class="modal-title" id="myModalLabel"><font color='blue'>选择部门</font></h4>
		            </div>
		            <div class="modal-body">
		            	<div id="prot4" style="height:360px;">
		            		<div class="col-md-12 col-sm-12 col-xs-12 text-center">
		            			<h4>请点击选择部门</h4>
								<ul id="treeDemo3" class="ztree"></ul>
							</div>	
		        		</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		                	<button type="button" class="btn btn-primary" id ="SelectOfficeBtnSub2">确定</button>
	                	</div>
		        	</div> 
				</div><!-- /.modal-content -->
		    </div><!-- /.modal -->
		</div>
		<!-- end(officeModal1) -->
		
		<div class="modal fade" id="updateUserModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		    <div class="modal-dialog" style="width:600px;">
		        <div class="modal-content">
		            <div class="modal-header">
		                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		                <h4 class="modal-title" id="myModalLabel"><font color='blue'>修改用户</font></h4>
		            </div>
		            <div class="modal-body">
		            	<div id="prot5" style="height:450px;overflow:auto;">
		            		<form id="UpdateUserform" class="form-horizontal">
					      		 <div class="col-md-11 col-sm-11 col-xs-12 mar">
					      		 	<div class="form-group">
										<div class="input-group">
											<input class="form-control hidden" name="id" type="text">
											<span class="input-group-addon">归属公司</span><input class="form-control hidden" name="companyId" type="text"><input class="form-control" name="companyName" readonly="readonly" type="text"><span class="input-group-btn"><button class="btn btn-default" style="height:34px;" id="updateCompanyShow" type="button"><i class="fa fa-search"></i></button></span>
										</div>
									</div>
								</div>
								<div class="col-md-11 col-sm-11 col-xs-12 mar">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon">归属部门</span><input class="form-control hidden" name="officeId" type="text"><input class="form-control" name="officeName" readonly="readonly" type="text"><span class="input-group-btn"><button class="btn btn-default" style="height:34px;" id="updateOfficeShow" type="button"><i class="fa fa-search"></i></button></span>
										</div>
									</div>
								</div>
								<div class="col-md-11 col-sm-11 col-xs-12 mar">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon">姓名:</span><input type="text" name="name" class="form-control">
										</div>
									</div>
								</div>
								<div class="col-md-11 col-sm-11 col-xs-12 mar">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon">性别:</span><input type="radio" name="sex" id="sexF" value="F">女&nbsp;&nbsp;<input
												type="radio" name="sex" id="sexM" value="M">男
										</div>
									</div>
								</div>
							    <div class="col-md-11 col-sm-11 col-xs-12 mar">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon">邮箱:</span><input type="text" name="email" class="form-control">
										</div>
									</div>
								</div>
								<div class="col-md-11 col-sm-11 col-xs-12 mar">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon">电话:</span><input type="text" name="phone" class="form-control">
										</div>
									</div>
								</div>
								<div class="col-md-11 col-sm-11 col-xs-12 mar">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon">手机:</span><input type="text" name="mobile" class="form-control">
										</div>
									</div>
								</div>
								<div class="col-md-3 col-sm-3 col-xs-12 mar">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon">在职情况</span><select class="form-control" style="width:200px" id ="updateDelFlag" name="delFlag"><option value="0">在职</option><option value="1">离职</option></select>
										</div>
				                 	</div>
								</div>
								<div class="col-md-11 col-sm-11 col-xs-12 mar">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon">入职日期:</span><input type="text" name="entryTime" class="form-control Wdate" onfocus="WdatePicker({el:this, dateFmt:'yyyy-MM-dd', readOnly:true, onpicked:checkProductionDate(this)})"/>
										</div>
									</div>	
								</div>
								<div class="col-md-11 col-sm-11 col-xs-12 mar">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon">试用期(月):</span><input type="text" name="tryTime" class="form-control">
										</div>
									</div>
								</div>
								<div class="col-md-11 col-sm-11 col-xs-12 mar">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon">实际转正日:</span><input type="text" name="actualTime" class="form-control Wdate" onfocus="WdatePicker({el:this, dateFmt:'yyyy-MM-dd', readOnly:true, onpicked:checkProductionDate(this)})">
										</div>
									</div>
								</div>
								<div class="col-md-11 col-sm-11 col-xs-12 mar">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon">用户角色:</span><div class="col-sm-10" id="roleIds2"></div>
										</div>
									</div>
								</div>
								<div class="col-md-11 col-sm-11 col-xs-12 mar">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon">备注:</span><textarea class="form-control" cols="40" rows="3" name="remarks"></textarea>
										</div>
									</div>
								</div>
							</form>
		        		</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		                	<button type="button" class="btn btn-primary" id ="updateUserBtn">确定</button>
	                	</div>
		        	</div> 
				</div><!-- /.modal-content -->
		    </div><!-- /.modal -->
		</div>
		
		<!-- 模态框(companyModal2) -->
		<div class="modal fade" id="companyModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		    <div class="modal-dialog">
		        <div class="modal-content">
		            <div class="modal-header">
		                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		                <h4 class="modal-title" id="myModalLabel"><font color='blue'>选择公司</font></h4>
		            </div>
		            <div class="modal-body">
		            	<div id="prot6" style="height:360px;">
						     <div class="col-md-12 col-sm-12 col-xs-12 text-center">
						     	<h4>请点击选择公司</h4>
								<ul id="treeDemo4" class="ztree"></ul>
							</div>	
		        		</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		                	<button type="button" class="btn btn-primary" id ="SelectCompanyBtnSub3">确定</button>
	                	</div>
		        	</div> 
				</div><!-- /.modal-content -->
		    </div><!-- /.modal -->
		</div>
		<!-- end(companyModal2) -->
		
		<!-- 模态框(officeModal2) -->
		<div class="modal fade" id="officeModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		    <div class="modal-dialog">
		        <div class="modal-content">
		            <div class="modal-header">
		                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		                <h4 class="modal-title" id="myModalLabel"><font color='blue'>选择部门</font></h4>
		            </div>
		            <div class="modal-body">
		            	<div id="prot7" style="height:360px;">
		            		<div class="col-md-12 col-sm-12 col-xs-12 text-center">
		            			<h4>请点击选择部门</h4>
								<ul id="treeDemo5" class="ztree"></ul>
							</div>	
		        		</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		                	<button type="button" class="btn btn-primary" id ="SelectOfficeBtnSub3">确定</button>
	                	</div>
		        	</div> 
				</div><!-- /.modal-content -->
		    </div><!-- /.modal -->
		</div>
		<!-- end(officeModal2) -->
		
	</div>
</div>

<script type="text/javascript">
$(function () {
    $('#myTab a:last').tab('show');//初始化显示哪个tab
  
    $('#myTab a').click(function (e) {
      e.preventDefault();//阻止a链接的跳转行为
      $(this).tab('show');//显示当前选中的链接及关联的content
    });
  });
function loadUserInfo(){
	$("#userListTable").bootstrapTable({
		url : 'user/page', // 请求后台的URL（*）
		method : 'post', // 请求方式（*）
		striped : true, // 是否显示行间隔色
		cache : false, // 是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
		pagination : true, // 是否显示分页（*）
		sortable : false, // 是否启用排序
		sortOrder : "asc", // 排序方式
		queryParams : function(params){
			console.log($("#UserInfoParams").serialize());
			return $("#UserInfoParams").serialize()+"&limit="+params.limit+"&offset="+params.offset;
		},// 传递参数（*）
		sidePagination : "server", // 分页方式：client客    户端分页，server服务端分页（*）
		pageNumber : 1, // 初始化加载第一页，默认第一页
		pageSize : 10, // 每页的记录行数（*）
		pageList : [ 10, 20], // 可供选择的每页的行数（*）
		contentType : "application/x-www-form-urlencoded",
		strictSearch : true,
		clickToSelect : true, // 是否启用点击选中行
		idField : "id", // 每一行的唯一标识，一般为主键列
        singleSelect:true,  //单选
		responseHandler :function(rs){
			console.log(rs);//{"msg":,"status",result}
			var status = rs.status;// 在此做了错误代码的判断
			if (status != 200) {
				alert("错误代码" + rs.msg);
				return;
			}
			// 如果没有错误则返回数据，渲染表格
			return {
				total : rs.result.total,
				rows : rs.result.list
			};
		},
		columns : [{
			field: 'ck',
			checkbox:true
		}, {
			field : 'company.name',
			title : '归属公司'
		}, {
			field : 'office.name',
			title : '归属部门'
		}, {
			field : 'no',
			title : '工号',
			formatter:nullFormat
		}, {
			field : 'name',
			title : '姓名',
			formatter:nullFormat
		}, {
			field : 'phone',
			title : '电话',
			formatter:nullFormat
		}, {
			field : 'mobile',
			title : '手机',
			formatter:nullFormat
		}, {
			field : 'delFlag',
			title : '在职情况',
			formatter:function(value, row, index) {
				if (value == '' || value == null) {
					return "";
				}
				return value==0?'在职':'离职';
			}
		}],
		onCheck: getSelectedRow,
		onUncheck: unGetSelectedRow
	});
}
//将null(对象空)转化为""(字符空)
function nullFormat(value, row, index) {
	if (value == '' || value == null) {
		return "";
	}
	return value;
}
//页面刷新就加载所有用户信息
$(function(){
	loadUserInfo();
});

//根据'查询'按钮 ,点击事件,按条件查询用户信息
$("#findUserbtn").click(function(){
	$("#userListTable").bootstrapTable('destroy');
	loadUserInfo();
	$("#UserInfoParams")[0].reset();
});



//配置节点参数
var setting = {	
		check:{           
            enable: false //每个节点上是否显示 CheckBox
        },
        data: {        	
        	 key : {
               title : "name",    
               name : "name"
             },
            simpleData: {//简单数据模式
                enable:true,
                idKey: "id",
                pIdKey: "parentId",
                rootPId: null
            }
        },
        callback:{          	
        		onClick: zTreeOnClick        	
       }       
    };	

//显示机构信息
function  showOffice(obj1,obj2){
	$.ajax({
		url:obj1,	
		type:'post',
		dataType:'json',
		data:obj2,
		success:function(data){
			if(data.status==200){
				var type  = data.result;
				$.fn.zTree.init($("#treeDemo"), setting, type);	
				$.fn.zTree.init($("#treeDemo1"), setting, type);	
				$.fn.zTree.init($("#treeDemo2"), setting, type);	
				$.fn.zTree.init($("#treeDemo3"), setting, type);	
				$.fn.zTree.init($("#treeDemo4"), setting, type);	
				$.fn.zTree.init($("#treeDemo5"), setting, type);	
			}
		}
	});
}
//机构信息树的回调函数
function zTreeOnClick(){
	CtrlSelectCompanyBtnSub();
	CtrlSelectCompanyBtnSub1();//控制增加用户里面的SelectCompanyBtnSub1
	CtrlSelectCompanyBtnSub2();//控制修改用户里面的SelectCompanyBtnSub3
	CtrlSelectOfficeBtnSub();
	CtrlSelectOfficeBtnSub1();//控制增加用户里面的SelectOfficeBtnSub1
	CtrlSelectOfficeBtnSub2();//控制修改用户里面的SelectOfficeBtnSub3
};

//查询用户，获取被选中的节点arry(json)
function selectedNodes1() {
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
	var nodes = treeObj.getSelectedNodes();
	return nodes;
};
//查询用户，获取被选中的节点arry(json)
function selectedNodes2() {
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo1");
	var nodes = treeObj.getSelectedNodes();
	return nodes;
};
//增加用户，获取被选中的节点arry(json)
function selectedNodes3() {
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo2");
	var nodes = treeObj.getSelectedNodes();
	return nodes;
};
//增加用户，获取被选中的节点arry(json)
function selectedNodes4() {
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo3");
	var nodes = treeObj.getSelectedNodes();
	return nodes;
};
//修改用户，获取被选中的节点arry(json)
function selectedNodes5() {
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo4");
	var nodes = treeObj.getSelectedNodes();
	return nodes;
};
//修改用户，获取被选中的节点arry(json)
function selectedNodes6() {
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo5");
	var nodes = treeObj.getSelectedNodes();
	return nodes;
};

//查询用户，展示公司
$("#companyShow").click(function(){
	showOffice('office/list',null);
	$("#companyModal").modal('show');
});

//查询用户，展示部门
$("#officeShow").click(function(){
	showOffice('office/list',null);
	$("#officeModal").modal('show');
});

//查询用户，判断公司选择按钮是否有效
function CtrlSelectCompanyBtnSub() {
	var nodes = selectedNodes1();
	if(nodes.length>0) {
		if(nodes[0].isParent) {       
			$("#SelectCompanyBtnSub").prop("disabled", false);//如果被选中的节点是父节点，则设置该删除按钮有效
		}else{
			//如果被选中的节点是子节点，则设置该删除按钮无效
			$("#SelectCompanyBtnSub").prop("disabled", true);	
		}
	}
}; 

//增加用户，判断公司选择按钮是否有效
function CtrlSelectCompanyBtnSub1() {
	var nodes = selectedNodes3();
	if(nodes.length>0) {
		if(nodes[0].isParent) {       
			$("#SelectCompanyBtnSub2").prop("disabled", false);//如果被选中的节点是父节点，则设置该删除按钮有效
		}else{
			//如果被选中的节点是子节点，则设置该删除按钮无效
			$("#SelectCompanyBtnSub2").prop("disabled", true);	
		}
	}
}; 

//修改用户，判断公司选择按钮是否有效
function CtrlSelectCompanyBtnSub2() {
	var nodes = selectedNodes5();
	if(nodes.length>0) {
		if(nodes[0].isParent) {       
			$("#SelectCompanyBtnSub3").prop("disabled", false);//如果被选中的节点是父节点，则设置该删除按钮有效
		}else{
			//如果被选中的节点是子节点，则设置该删除按钮无效
			$("#SelectCompanyBtnSub3").prop("disabled", true);	
		}
	}
}; 

//查询用户，判断部门选择按钮是否有效
function CtrlSelectOfficeBtnSub() {
	var nodes = selectedNodes2();
	if(nodes.length>0) {
		if(nodes[0].isParent) {     
			//如果被选中的节点是父节点，则设置该删除按钮有效
			$("#SelectOfficeBtnSub").prop("disabled", true);	
		}else{
			$("#SelectOfficeBtnSub").prop("disabled", false);//如果被选中的节点是子节点，则设置该删除按钮无效
		}
	}
}; 

//增加用户，判断部门选择按钮是否有效
function CtrlSelectOfficeBtnSub1() {
	var nodes = selectedNodes4();
	if(nodes.length>0) {
		if(nodes[0].isParent) {     
			//如果被选中的节点是父节点，则设置该删除按钮有效
			$("#SelectOfficeBtnSub2").prop("disabled", true);	
		}else{
			$("#SelectOfficeBtnSub2").prop("disabled", false);//如果被选中的节点是子节点，则设置该删除按钮无效
		}
	}
}; 

//修改用户，判断部门选择按钮是否有效
function CtrlSelectOfficeBtnSub2() {
	var nodes = selectedNodes6();
	if(nodes.length>0) {
		if(nodes[0].isParent) {     
			//如果被选中的节点是父节点，则设置该删除按钮有效
			$("#SelectOfficeBtnSub3").prop("disabled", true);	
		}else{
			console.log('不是父节点');				 
			console.log(nodes[0].id);
			$("#SelectOfficeBtnSub3").prop("disabled", false);//如果被选中的节点是子节点，则设置该删除按钮无效
		}
	}
};


//查询用户，向input框里放入company的ID和name
$("#SelectCompanyBtnSub").click(function(){
	var nodes = selectedNodes1();
	if(nodes.length>0) {
		$("#UserInfoParams input[name='companyName']").val(nodes[0].name);
		$("#UserInfoParams input[name='companyId']").val(nodes[0].id);
	}
	$("#companyModal").modal('hide');
});

//查询用户，向input框里放入office的ID和name
$("#SelectOfficeBtnSub").click(function(){
	var nodes = selectedNodes2();
	if(nodes.length>0) {
		$("#UserInfoParams input[name='officeName']").val(nodes[0].name);
		$("#UserInfoParams input[name='officeId']").val(nodes[0].id);
	}
	$("#officeModal").modal('hide');
});
</script>
<script>
//验证新增用户表单
function formValidator(oneform) {
	 $(oneform).bootstrapValidator({
		live : 'enabled', //验证时机，enabled是内容有变化就验证（默认），disabled和submitted是提交再验证  
		excluded : [ ':disabled', ':hidden', ':not(:visible)' ], //排除无需验证的控件，比如被禁用的或者被隐藏的  
		//submitButtons : '#btn-test', //指定提交按钮，如果验证失败则变成disabled，但我没试成功，反而加了这句话非submit按钮也会提交到action指定页面  
		message : '通用的验证失败消息', //好像从来没出现过  
		feedbackIcons : { //根据验证结果显示的各种图标  
			valid : 'glyphicon glyphicon-ok',
			invalid : 'glyphicon glyphicon-remove',
			validating : 'glyphicon glyphicon-refresh'
		},
		fields : {
			companyName : {
				validators : {
					notEmpty : {
						message : '请选择公司名'
					}
				}
			},
			officeName : {
				validators : {
					notEmpty : {
						message : '请选择部门名'
					}
				}
			},
			name : {
				validators : {
					notEmpty : {
						message : '请输入姓名'
					}
				}
			},
			no: {//验证input项：验证规则
                 message: '工号',
                 validators: {
                     notEmpty: {//非空验证：提示消息
                         message: '工号不能为空'
                     },
                     stringLength: {
                         min: 1,
                         max: 10,
                         message: '工号长度必须在1到10之间'
                     },
                     threshold :  6 , //有6字符以上才发送ajax请求，（input中输入一个字符，插件会向服务器发送一次，设置限制，6字符以上才开始）
                     remote: {//ajax验证。server result:{"valid",true or false} 向服务发送当前input name值，获得一个json数据。例表示正确：{"valid",true}  
                         url: 'user/checkno',//验证地址
                         message: '工号已存在',//提示消息
                         delay :  2000,//每输入一个字符，就发ajax请求，服务器压力还是太大，设置2秒发送一次ajax（默认输入一个字符，提交一次，服务器压力太大）
                         type: 'POST'//请求方式
                     },
                     regexp: {
                         regexp: /^[a-zA-Z0-9_\.]+$/,
                         message: '工号由数字字母下划线和.组成'
                     }
                 }
             },
             loginName: {//验证input项：验证规则
                 message: '登录名',
                 validators: {
                     notEmpty: {//非空验证：提示消息
                         message: '登录名不能为空'
                     },
                     stringLength: {
                         min: 1,
                         max: 10,
                         message: '登录名长度必须在1到10之间'
                     },
                     threshold :  5 , //有6字符以上才发送ajax请求，（input中输入一个字符，插件会向服务器发送一次，设置限制，6字符以上才开始）
                     remote: {//ajax验证。server result:{"valid",true or false} 向服务发送当前input name值，获得一个json数据。例表示正确：{"valid",true}  
                         url: 'user/checkLoginName',//验证地址
                         message: '登录名已存在',//提示消息
                         delay :  2000,//每输入一个字符，就发ajax请求，服务器压力还是太大，设置2秒发送一次ajax（默认输入一个字符，提交一次，服务器压力太大）
                         type: 'POST'//请求方式
                     },
                     regexp: {
                         regexp: /^[a-zA-Z0-9_\.]+$/,
                         message: '登录名由数字字母下划线和.组成'
                     }
                 }
             },
             password: {
                 message:'密码无效',
                 validators: {
                     notEmpty: {
                         message: '密码不能为空'
                     },
                     stringLength: {
                         min: 6,
                         max: 30,
                         message: '密码长度必须在6到30之间'
                     },
                     different: {//不能和用户名相同
                         field: 'loginName',//需要进行比较的input name值
                         message: '不能和用户名相同'
                     },
                     regexp: {
                         regexp: /^[a-zA-Z0-9_\.]+$/,
                         message: '密码由数字字母下划线和.组成'
                     }
                 }
             },
             repassword: {
                 message: '密码无效',
                 validators: {
                     notEmpty: {
                         message: '密码不能为空'
                     },
                     stringLength: {
                         min: 6,
                         max: 30,
                         message: '密码长度必须在6到30之间'
                     },
                     identical: {//相同
                         field: 'password',
                         message: '两次密码不一致'
                     }
                 }
             },
             email: {
                 validators: {
                     notEmpty: {
                         message: '邮件不能为空'
                     },
                     emailAddress: {
                         message: '请输入正确的邮件地址如：123@qq.com'
                     },
                     regexp: {
                         regexp: /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
                         message: '邮箱格式不正确'
                     }
                 }
             },
             phone: {
                 message: '电话无效',
                 validators: {
                     notEmpty: {
                         message: '电话不能为空'
                     },
                     regexp: {
                    	 //regexp: /^(\d{2,4}[-_－—]?)?\d{3,8}([-_－—]?\d{3,8})?([-_－—]?\d{1,7})?$)|(^0?1[35]\d{9}$/,
                         // regexp: /^(0\d{2})-(\d{8})$)|(^(0\d{3})-(\d{7})$)|(^(0\d{2})-(\d{8})-(\d+)$)|(^(0\d{3})-(\d{7})-(\d+)$/,
						regexp:/^0\d{2,3}-[1-9]\d{6,7}$/,
                        message: '请输入正确的电话号码'
                     }
                 }
             },
             mobile: {
                 message: '手机号码无效',
                 validators: {
                     notEmpty: {
                         message: '手机号码不能为空'
                     },
                     stringLength: {
                         min: 11,
                         max: 11,
                         message: '请输入11位手机号码'
                     },
                     regexp: {
                         regexp: /^1[3|5|8]{1}[0-9]{9}$/,
                         message: '请输入正确的手机号码'
                     }
                 }
             },
			entryTime: {
				validators: {
					notEmpty: {
					    message: '请输入入职日期'
					}
				}
			},
			tryTime: {//试用期
				validators: {
					notEmpty: {
					    message: '试用期时间'
					},
					 stringLength: {
                         min: 1,
                         max: 1,
                         message: '请输入1位数字'
                     },
                     regexp: {
                         regexp: /^[0-6]$/,
                         message: '请输入正确的试用期限：0-6'
                     }
				}
			},
			actualTime: {
				validators: {
					notEmpty: {
					    message: '请输入实际转正日期'
					}
				}
			},
			roleIds: {//checkbox验证
				validators: {
				    notEmpty: {
				        message: '请选择用户角色'
				    }
				}
			}
			
		}
	}); 
};

$(function(){
	formValidator("#userform");
	formValidator("#UpdateUserform");
	}); //在js默认启动时调用formValidator()启动校验form
	
//验证时间
function checkProductionDate(obj)
{
	 console.log(obj.name);
	 if(obj.value!=null && obj.value!="" && obj.value!=undefined)
	 {
	      $("#userform").data("bootstrapValidator").updateStatus(obj.name,"NOT_VALIDATED", null).validateField(obj.name);
	      $("#UpdateUserform").data("bootstrapValidator").updateStatus(obj.name,"NOT_VALIDATED", null).validateField(obj.name);
	}
}
</script>
<script>
//查询所有的角色
$.ajax({
	   type: "post",
	   url: "role/list",
	   dataType:"json",
	   success: function(data){
	    if(data.status==200){
	    	var roles=data.result;
	    	for(i=0;i<roles.length;i++){
	    		$("#roleIds").append("<input type='checkbox' name='roleIds' value='"+roles[i].id+"'>"+roles[i].name+"&nbsp;");
	    		$("#roleIds2").append("<input type='checkbox' name='roleIds' value='"+roles[i].id+"'>"+roles[i].name+"&nbsp;");
	    	}
	    }
	   },
	   error:function(data){
		  console.log(data.msg);
	   }
});



//增加用户，展示公司
$("#companyShow2").click(function(){
	showOffice('office/list',null);
	$("#companyModal1").modal('show');
});

//增加用户，展示部门
$("#officeShow2").click(function(){
	showOffice('office/list',null);
	$("#officeModal1").modal('show');
});

//增加用户，向userform下input框里放入company的ID和name
$("#SelectCompanyBtnSub2").click(function(){
	var nodes = selectedNodes3();
	if(nodes.length>0) {
		$("#userform input[name='companyName']").val(nodes[0].name);
		$("#userform input[name='companyId']").val(nodes[0].id);
	}
	$("#companyModal1").modal('hide');
});

//增加用户，向userform下input框里放入office的ID和name
$("#SelectOfficeBtnSub2").click(function(){
	var nodes = selectedNodes4();
	if(nodes.length>0) {
		$("#userform input[name='officeName']").val(nodes[0].name);
		$("#userform input[name='officeId']").val(nodes[0].id);
	}
	$("#officeModal1").modal('hide');
});

$(function(){
	$("#saveNewUser").click(function(){
		$("#userform").bootstrapValidator('validate'); //提交验证  
		if($("#userform").data('bootstrapValidator').isValid()) { 
			$.ajax({
			   url: "user/save",
			   type: "post",
			   dataType:"json",
			   data:$("#userform").serialize(),
			   success: function(data){
				   if(data.status==200){
				    	loadUserInfo();
				   }
			   },
			   error:function(data){
				  console.log(data.msg);
			   }	
			});
			$("#userform")[0].reset();
			$("#userform").data('bootstrapValidator').destroy();
			$("#userform").data('bootstrapValidator',null);
			formValidator("#userform");
		}
	});
});


function jsonDateFormat(jsonDate) {//json日期格式(毫秒)转换为date格式
    try {
        var date  = new Date(jsonDate);
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day   = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hour  = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var min   = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var sec   = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        return date.getFullYear() + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec;
    } catch (ex) {
        return "";
    }
}    

function jsonDateFormatYMD(jsonDate) {//json日期格式(毫秒)转换为date格式
    try {
        var date  = new Date(jsonDate);
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day   = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        return date.getFullYear() + "-" + month + "-" + day;
    } catch (ex) {
        return "";
    }
} 

var getRow = null;

//勾选用户对象
function getSelectedRow(row) {
	getRow = row;
}
//取消勾选用户对象
function unGetSelectedRow(row) {
	getRow = null;
}

//删除用户(就是修改用户的delflag属性，delflag = 0 :在职;delflag = 1：离职)
$("#btn_delete").click(function(){
	if(getRow == null) {
		alert("请单击选中用户!");
	}else {
		if(getRow.delFlag == 1) {
			alert("该用户已离职，无法删除!");
		}else {
			if (confirm("你确定要注销该用户吗？是－选择确定，否-选择取消")) {
				$.ajax({
					   type: "post",
					   url: "user/del",
					   dataType:"json",
					   data : {"id":getRow.id,
						   "updateDate":jsonDateFormat(getRow.updateDate)
						   },
					   success: function(data){
						   if(data.status==200){
							   alert(data.msg);
						   }
					   },
					   error:function(data){
						  console.log(data.msg);
					   }	
				});
			}
		}
		getRow = null;
		$("#userListTable").bootstrapTable('destroy');
		loadUserInfo(); 
	}
});

//准备修改用户，展示公司
$("#updateCompanyShow").click(function(){
	showOffice('office/list',null);
	$("#companyModal2").modal('show');
});

//准备修改用户，展示部门
$("#updateOfficeShow").click(function(){
	showOffice('office/list',null);
	$("#officeModal2").modal('show');
});


//准备修改用户，向input框里放入company的ID和name
$("#SelectCompanyBtnSub3").click(function(){
	var nodes = selectedNodes5();
	if(nodes.length>0) {
		$("#UpdateUserform input[name='companyName']").val(nodes[0].name);
		$("#UpdateUserform input[name='companyId']").val(nodes[0].id);
	}
	$("#companyModal2").modal('hide');
});

//准备修改用户，向input框里放入office的ID和name
$("#SelectOfficeBtnSub3").click(function(){
	var nodes = selectedNodes6();
	if(nodes.length>0) {
		$("#UpdateUserform input[name='officeName']").val(nodes[0].name);
		$("#UpdateUserform input[name='officeId']").val(nodes[0].id);
	}
	$("#officeModal2").modal('hide');
});

//准备修改用户
$("#btn_update").click(function(){
	if(getRow == null) {
		alert("请单击选中用户!");
	}else{
		$("#UpdateUserform input[name='id']").val(getRow.id);
		$("#UpdateUserform input[name='companyId']").val(getRow.companyId);
		$("#UpdateUserform input[name='companyName']").val(getRow.company.name);
		$("#UpdateUserform input[name='officeId']").val(getRow.officeId);
		$("#UpdateUserform input[name='officeName']").val(getRow.office.name);
		$("#UpdateUserform input[name='name']").val(getRow.name);
		//sex
		if(getRow.sex=="F") {   
			$("#sexF").attr("checked","checked");	
		}
		if(getRow.sex=="M"){
			$("#sexM").attr("checked","checked");
		}
		$("#UpdateUserform input[name='email']").val(getRow.email);
		$("#UpdateUserform input[name='phone']").val(getRow.phone);
		$("#UpdateUserform input[name='mobile']").val(getRow.mobile);
		// delflag
		if(getRow.delFlag == 0) {
			$("#updateDelFlag option[value='0']").attr("selected", true);
		}else{
			$("#updateDelFlag option[value='1']").attr("selected", true);
		}
		$("#UpdateUserform input[name='entryTime']").val(jsonDateFormatYMD(getRow.entryTime));
		$("#UpdateUserform input[name='tryTime']").val(getRow.tryTime);
		$("#UpdateUserform input[name='actualTime']").val(jsonDateFormatYMD(getRow.actualTime));
		//匹配角色
		$.ajax({
	 		url:'userRoleMgr/list',
	 		type:'post',
	 		data:{"id":getRow.id}, 
	 		dataType:'json', 
	 		success:function(data){
	 			if(data.status==200) {
	 				var roleIds = data.result; //这是一个包含roleId的数组
	 			 	$("#UpdateUserform input[name='roleIds']").removeAttr("checked");//取消被选中的checkedbox 
	 				$("#UpdateUserform input[name='roleIds']").each(
	 						function(index, domel){
	 							for(i=0; i<roleIds.length; i++) {
		 							if($(this).val()==roleIds[i].roleId) {
		 								$(this).prop("checked","checked"); //用prop选中checked
			 						}
	 							}
	 						}
	 					)
	 			}
	 		},
	 			error:function(result){
				console.log(error);
			}
	 	});  
		$("#UpdateUserform textarea[name='remarks']").val(getRow.remarks);
		$("#updateUserModal").modal('show');	
	}
});

$("#updateUserBtn").click(function(){
	$("#UpdateUserform").bootstrapValidator('validate'); //提交验证  
	if($("#UpdateUserform").data('bootstrapValidator').isValid()) { //获取验证结果，如果成功，执行下面代码  
		$.ajax({
			   type: "post",
			   url: "user/update",
			   dataType:"json",
			   data : $("#UpdateUserform").serialize(),
			   success: function(data){
				   if(data.status==200){
					   alert(data.msg);
					   getRow = null;
					   $("#userListTable").bootstrapTable('destroy');
					   loadUserInfo();
				   }
			   },
			   error:function(data){
				  console.log(data.msg);
			   }	
		});
		$("#updateUserModal").modal('hide');           
		$("#UpdateUserform")[0].reset();
	}
});

//在modal隐藏时移除校验重新添加校验
$("#updateUserModal").on('hidden.bs.modal',function(e){       
	//移除上次的校验配置
    $("#UpdateUserform").data('bootstrapValidator').destroy();
	$("#UpdateUserform").data('bootstrapValidator',null);
	//重新添加校验
	formValidator("#UpdateUserform");
});

</script>
</html>